﻿@model WebSite.Web.Models.LinksVM

@{
    ViewBag.Title = "友情链接";
    Layout = "~/Views/Shared/_ViewFormPage.cshtml";
}

@section head{
    <script type="text/javascript">
        $(function () {
            $("#btnSave").click(function () {
                if ($("form").valid()) {
                    $('form').ajaxSubmit({
                        success: function (callback) {
                            if (callback) {
                                $.ligerDialog.success('保存成功', function (yes) {
                                    self.location.href = "/Links/Edit";
                                });
                            }
                            else {
                                $.ligerDialog.error('保存失败');
                            }
                        },
                        error: function (ex) {
                            $.ligerDialog.error('保存失败');
                        }

                    });
                }
            });


            $("#productImage").click(function () {
                $("#fileUploader").trigger("click");
            });


            $("#fileUploader").change(function () {
                //创建FormData对象
                var data = new FormData();
                //为FormData对象添加数据
                $.each($(this)[0].files, function (i, file) {
                    data.append('imgFile', file);
                });
                $.ajax({
                    url: '/File/Upload',
                    type: 'POST',
                    data: data,
                    cache: false,
                    contentType: false,		//不可缺
                    processData: false,		//不可缺
                    success: function (data) {
                        if (data) {
                            $("#productImage").attr("src", JSON.parse(data).url);
                            $("#ImgUrl").val(JSON.parse(data).url);
                        }
                        //alert(JSON.parse(data).url);
                    },
                    error: function () {
                        alert('上传出错');
                    }
                });
            });

        });

    </script>
    @if (false)
    {
        <script src="../../Scripts/jquery-1.7.1.js"></script>
    }
    <style type="text/css">
    </style>
}
<div id="header" class="header">
    <h4>友情链接 -- 维护</h4>
</div>
@using (Html.BeginForm("Edit", "Links", FormMethod.Post))
{
    @Html.HiddenFor(model => model.CompanyId)
    @Html.HiddenFor(model => model.Id)
    <div id="detail_forms">
        <div class="formsItems clearfix">
            <div class="formItem labelItem">
                标题
            </div>
            <div class="formItem textItem">
                @Html.TextBoxFor(model => model.Title, new { @class = "texts" })
            </div>
            <div class="formItem msgItem">
            </div>
        </div>

        <div class="formsItems clearfix">
            <div class="formItem labelItem">
                图片
            </div>
            <div class="formItem textItem">
                <table border="0">
                    <tr>
                        <td>
                            <div id="showImage">
                                <img src='@Model.ImgUrl'  style="height:120px; cursor:pointer; width:200px;" alt="" id="productImage" />
                            </div>
                        </td>
                        <td style="vertical-align: bottom;">
                            <div style="width: 220px; margin-left: 10px; display: block">
                                <input type="file" id="fileUploader" style="display: none;" name="file_upload" />
                                @Html.HiddenFor(m => m.ImgUrl)
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="formItem msgItem">
            </div>
        </div>

        <div class="formsItems clearfix">
            <div class="formItem labelItem">
                链接地址
            </div>
            <div class="formItem textItem">
                @Html.TextBoxFor(model => model.Url, new { @class = "texts" })
            </div>
            <div class="formItem msgItem">
            </div>
        </div>



        <div id="btnContainer" class="formsItems">
            <div class="formItem labelItem">
                &nbsp;
            </div>
            <div class="formItem textItem">
                <a href="javascript:void(0);" id="btnSave">保存</a>
                <a href="Index" id="btnCancel">取消</a>
            </div>
            <div class="formItem">
            </div>
        </div>
        <div class="formsItems"></div>
    </div>
}
